package com.litq.education.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.litq.education.bean.GroupTable;
import com.litq.education.service.CustomerService;
import com.litq.education.service.GroupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * GroupController
 *
 * @author Litq
 * @version v1.0
 * @since 2019/2/10 1:30
 */
@RestController
public class GroupController {
    Logger logger = LoggerFactory.getLogger(GroupController.class);
    @Resource
    GroupService groupService;


    /**
     * @Method 查询活动表id和名称，用于前台下拉框
     * @Author Litq
     * @Version 1.0
     * @Description 用于前台下拉框
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/queryAllGroup", method = {RequestMethod.POST, RequestMethod.GET})
    public Object queryAllGroup() {
        logger.info("查询信息打印----------------------------------开始查询");

        List list = groupService.queryAllGroup();

        logger.info("查询信息打印----------------------------------打印结果" + list);
        return list;
    }


    /**
     * @Method 查询活动表id和名称，用于前台下拉框
     * @Author Litq
     * @Version 1.0
     * @Description 用于表格显示
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/queryAllGroup1", method = {RequestMethod.POST, RequestMethod.GET})
    public Object queryAllGroup1(@RequestBody(required = false) Map<String, Object> reqMap) {
        logger.info("查询信息打印----------------------------------开始查询");
        logger.info("查询信息打印----------------------------------是否有参数:" + reqMap);
        //current 第几页   number 一页多少条
        Map<String, Object> map = new HashMap<String, Object>();
        if (null == reqMap.get("groupName") || "".equals(reqMap.get("groupName"))) {
            int pageCount = Integer.parseInt(reqMap.get("page").toString());
            int limit = Integer.parseInt(reqMap.get("limit").toString());
            int count = groupService.selectListCount();
            logger.info("查询信息打印----------------------------------数据总条数:" + count);
            Page<Map<String, Object>> page = groupService.selectListPage(pageCount, limit);
            List list = page.getRecords();
            map.put("code", 0);
            map.put("msg", "用户数据表");
            map.put("count", count);
            map.put("data", list);
            return map;
        } else {
            int pageCount = Integer.parseInt(reqMap.get("page").toString());
            int limit = Integer.parseInt(reqMap.get("limit").toString());
            int count = groupService.selectListCount();
            String groupName = reqMap.get("groupName").toString();
            logger.info("查询信息打印----------------------------------参数" + groupName);
            logger.info("查询信息打印----------------------------------数据总条数:" + count);
            Page<Map<String, Object>> page = groupService.selectListPageByUserName(pageCount, limit, groupName);
            List list = page.getRecords();
            map.put("code", 0);
            map.put("msg", "用户数据表");
            map.put("count", count);
            map.put("data", list);
            return map;
        }
    }

    /**
     * @Method 根据id删除活动
     * @Author Litq
     * @Version 1.0
     * @Description 根据id删除活动
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/deleteGroupById", method = {RequestMethod.POST, RequestMethod.GET})
    public Object deleteById(@RequestBody Map<String, Object> reqMap) {
        logger.info("删除信息打印----------------------------------开始删除");
        logger.info("删除信息打印----------------------------------是否有参数:" + reqMap);

        int id = Integer.parseInt(reqMap.get("id").toString());

        logger.info("查询信息打印----------------------------------是否有参数:" + id);
        int sign = groupService.deleteById(id);
        return sign;
    }

    /**
     * @Method 根据id查询活动
     * @Author Litq
     * @Version 1.0
     * @Description 根据id查询活动
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/queryAllGroupById", method = {RequestMethod.POST, RequestMethod.GET})
    public Object queryAllGroupById(@RequestBody(required = false) Map<String, Object> reqMap) {
        logger.info("查询信息打印----------------------------------开始查询");
        logger.info("查询信息打印----------------------------------是否有参数:" + reqMap);
        String id = reqMap.get("id").toString();

        Map map = groupService.queryAllGroupById(id);
        return map;
    }

    /**
     * @Method 根据id修改活动
     * @Author Litq
     * @Version 1.0
     * @Description 根据id修改活动
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/updateGroupById", method = {RequestMethod.POST, RequestMethod.GET})
    public Object updateGroupById(@RequestBody(required = false) Map<String, Object> reqMap) {
        logger.info("查询信息打印----------------------------------开始修改");
        logger.info("查询信息打印----------------------------------是否有参数:" + reqMap);
        String id = reqMap.get("id").toString();

        int sign = groupService.updateGroupById(reqMap);
        return sign;
    }
    /**
     * @Method 添加活动
     * @Author Litq
     * @Version 1.0
     * @Description
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/insertGroup", method = {RequestMethod.POST, RequestMethod.GET})
    public Object insertGroup(@RequestBody(required = false) Map<String, Object> reqMap) {
        logger.info("修改信息打印----------------------------------开始修改");
        logger.info("修改信息打印----------------------------------是否有参数:" + reqMap);


        int sign =groupService.insertGroup(reqMap);
        logger.info("修改信息打印----------------------------------打印标志:" + sign);
        return sign;
    }

}
